package sort;

/**
 * Created with IntelliJ IDEA.
 * Description: 选择排序
 * User: Li_yizYa
 * Date: 2025/9/8
 * Time: 22:26
 */
// 6  5  4  4  3  1  2  10  8
//
public class SelectSort {
    public static void selectSort(int[] nums) {
        if (nums == null || nums.length == 0) {
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            int minIndex = i; // 记录最小值的下标
            for (int j = i; j < nums.length; j++) {
                if (nums[minIndex] > nums[j]) {
                    minIndex = j;
                }
            }
            int tmp = nums[minIndex];
            nums[minIndex] = nums[i];
            nums[i] = tmp;
        }
    }

    public static void main(String[] args) {
        int[] nums = {6,5,4,4,3,1,2,10,8};
        selectSort(nums);
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }
}
